package com.eascs.spider.kuaixiao.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class DBUtil {

	private static Properties db = new Properties();
	
	static{
		InputStream is = DBUtil.class.getClassLoader().getResourceAsStream("db.properties");
		try {
			db.load(is);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static Map<String, String> getProperties(){
		String environment = db.getProperty("environment");
		Map<String, String> map = new HashMap<>();
		map.put("mongodb.ip", db.getProperty(environment+".mongodb.ip"));
		map.put("mongodb.port", db.getProperty(environment+".mongodb.port"));
		map.put("mongodb.user", db.getProperty(environment+".mongodb.user"));
		map.put("mongodb.password", db.getProperty(environment+".mongodb.password"));
		map.put("mongodb.library", db.getProperty(environment+".mongodb.library"));
		
		map.put("redis.ip", db.getProperty(environment+".redis.ip"));
		map.put("redis.port", db.getProperty(environment+".redis.port"));
		map.put("redis.password", db.getProperty(environment+".redis.password"));
		
		return map;
	}
}
